<?php
	include_once("global.php");
	session_start();
	$uid = $_SESSION['name'];
	$smarty->assign("uid",$uid);
	
	//头部
	$sql_select_search = "select K_Name,K_KID from keywordinfo where K_search > '1' limit 0,4";
	$query_select_search = $mysqli->query($sql_select_search);
	while($result_select_search = $query_select_search->fetch_assoc()){
		$assign_search[] = array(	"num"	=>	$result_select_search['K_KID'],
									"name"	=>	$result_select_search['K_Name']);
	}
	$smarty->assign("assign_search",$assign_search);/*热门关键词*/
	
	$sql_select_skeyword = "select K_Name,K_KID from keywordinfo where K_search = '1'";
	$query_select_skeyword = $mysqli->query($sql_select_skeyword);
	while($result_select_skeyword = $query_select_skeyword->fetch_assoc()){
		$assign_skeyword[] = array(	"num"	=>	$result_select_skeyword['K_KID'],
									"name"	=>	$result_select_skeyword['K_Name']);
	}
	$smarty->assign("assign_skeyword",$assign_skeyword);/*搜索框内关键词*/
	
	$sql_select_articlecategory = "select * from categoryinfo limit 0,2";
	$query_select_articlecategory = $mysqli->query($sql_select_articlecategory);
	while($result_select_articlecategory = $query_select_articlecategory->fetch_assoc()){
		$assign_artcategory[] = array (	"id"	=>	$result_select_articlecategory['C_CID'],
										"name"	=>	$result_select_articlecategory['C_Categoryname']);
	}
	$smarty->assign("assign_artcategory",$assign_artcategory);/*导航条*/
	
	$sql_select_countapp = "select * from appinfo";
	$query_select_countapp = $mysqli->query($sql_select_countapp);
	$result_select_countapp = $query_select_countapp->num_rows;
	$assign_countapp = $result_select_countapp;
	$smarty->assign("assign_countapp",$assign_countapp);/*站内APP统计*/
	
	$random = mt_rand(50,$assign_countapp);
	$assign_radnom = $random;
	$smarty->assign("assign_radnom",$assign_radnom);	
	
	//通栏推广位
	$sql_select_banner = "select * from pushinfo where P_Pushid >30";
	$query_select_banner = $mysqli->query($sql_select_banner);
	while($result_select_banner = $query_select_banner->fetch_assoc()){
		$banner_appid = $result_select_banner['P_Pushappid'];
		$banner_apppid = $result_select_banner['P_Pushpid'];
		
		$sql_select_bannerpic = "select * from pictureinfo where P_PID = '$banner_apppid'";
		$query_select_bannerpic = $mysqli->query($sql_select_bannerpic);
		$result_select_bannerpic = $query_select_bannerpic->fetch_assoc();
		
		$sql_select_bannerapp = "select * from appinfo where A_Apptrackid = '$banner_appid'";
		$query_select_bannerapp = $mysqli->query($sql_select_bannerapp);
		$result_select_bannerapp = $query_select_bannerapp->fetch_assoc();
		
		$assign_bannerapp[] = array(	"id"	=>	$banner_appid,
										"name"	=>	$result_select_bannerapp['A_Apptrackname'],
										"url"	=>	"images/".$result_select_bannerpic['P_Name'].".png",);
	}
	$smarty->assign("assign_bannerapp",$assign_bannerapp);/*顶部通栏，首页通栏1，首页通栏2*/	
//	//APP排行榜
	$sql_app_rank = "select * from appinfo where A_Appprice = '免费' order by A_Appdate desc limit 0,6";
	$query_app_rank = $mysqli->query($sql_app_rank);
	while($result_app_rank = $query_app_rank->fetch_assoc()){
		$assign_apprank[] = array(	"id"	=>	$result_app_rank['A_Appid'],
									"name"	=>	$result_app_rank['A_Apptrackname'],
									"icon"	=>	$result_app_rank['A_Appicon'],
								);
	}
	$smarty->assign("assign_apprank",$assign_apprank);/*免费排名*/
	
	$sql_site_info = "select * from siteinfo";
	$query_site_info = $mysqli->query($sql_site_info);
	while($result_site_info = $query_site_info->fetch_assoc()){
		$assign_info[] = array(	"id"	=>	$result_site_info['S_SID'],
								"info"	=>	$result_site_info['S_Name'],
							);
	}
	$smarty->assign("assign_info",$assign_info);
	
	$url = $_SERVER['REQUEST_URI'];
	$url_arr = parse_url($url);
	parse_str($url_arr['query'],$url_arr);
	$id = $url_arr[id];
	if($id == $uid){
		$sql_select_uid = "select * from userinfo where U_UID = '$uid'";
		$query_select_uid = $mysqli->query($sql_select_uid);
		$result_select_uid = $query_select_uid->fetch_assoc();
		$inte = $result_select_uid['U_Integral']-$result_select_uid['U_Consume'];
		$assign_uid = array(	"name"	=>	$result_select_uid['U_Loginid'],
								"inte"	=>	$inte,
								"email"	=>	$result_select_uid['U_email'],
							);
		$smarty->assign("assign_uid",$assign_uid);
		

	}else{
		echo "<meta http-equiv=\"refresh\" content=\"1; url='member.php?id=".$uid."' />";
	}
	
	if(isset($_POST['changepwd'])){
		if($_POST['pwd'] == $_POST['repeatpwd']){
			$new_pwd = md5($_POST['pwd']."game818");
			$sql_update_pwd = "update userinfo set U_Password = '$new_pwd' where U_UID = '$uid'";
			$query_update_pwd = $mysqli->fetch_assoc();
			if($query_update_pwd){
				echo "<script>alert('修改成功')</script>";	
			}else{
				echo "<script>alert('修改失败，请返回重新修改')</script>";
			}
			echo $sql_update_pwd;
		}else{
			echo "<script>alert('修改失败，两次密码不一致')</script>";
		}
	}

	$smarty->display("member.html");
	$smarty->display("footer.html");
	
?>